<template>
	<view class="content">
		<view class="jiemian">
			<!-- 显示背景图片 -->
			<view class="backgroundX" :style="{backgroundImage:`url(${background_image})`,color:`white`}">
				<!-- 显示正文内容 -->
				<view class="backgroundXText" id="backgroundXText">
					<view v-if="shiguangzhuisushijie!='0'" style="font-size: 15px;">
						时光追溯世界
						<!-- 分割线 -->
						<u-divider></u-divider>
					</view>
					<view v-if="newjuqingbiaoji!=0" style="font-size: 16px;">
						新世界
						<!-- 分割线 -->
						<u-divider></u-divider>
					</view>
					<view v-if="teshubiaoji!='0'" style="font-size: 15px;">
						第{{teshubiaoji}}世界
						<!-- 分割线 -->
						<u-divider></u-divider>
					</view>
					<text v-for="(line, index) in lines" :key="index">{{ line }}</text>
				</view>
				<!-- 正文显示完才显示按钮-->
				<view v-if="juqinganniushow" style="position: fixed;bottom: 11.3%;width: 60vw">
					<!-- 对话框按钮 -->
					<button @click="duihuashow=true" v-if="juqinganniu==1">{{duihuaanniu}}</button>
					<!-- 下一章节按钮 -->
					<button @click="juqing()" v-else-if="juqinganniu==0">{{duihuaanniu}}</button>
					<!-- 对战按钮，对战期间禁灰 -->
					<button @click="getduzhanshow" v-else-if="juqinganniu==2" :disabled="duzhandisabled">{{duihuaanniu}}</button>
				</view>
			</view>
			<view class="menuX">
				<u-button :text="dibuanniu1" @click="openBag" :disabled="duzhandisabled"></u-button>
				<!-- <u-button text="闭关"></u-button> -->
				<u-button :text="dibuanniu2" @click="openYunYou" :disabled="duzhandisabled"></u-button>
			</view>
		</view>
		<!-- 对话弹框 -->
		<u-modal :show="duihuashow" :confirmText="duihuaanniu" @confirm="duihua">
			<view class="duihuakuangclass">
				<rich-text :nodes="duihuacontent"></rich-text>
			</view>
		</u-modal>
		<!-- 对战弹窗 -->
		<view v-show="duzhanshow" class="duizhanshow">
			<view class="duizhanshowbody">
				<view>对战</view>
				<!-- 生命值 -->
				<view class="shuangfsmz">
					<view v-if="zhujuesmzcopy>0">{{zhujuesmzcopy}}<text style="font-size: 12px;">(LV.{{zhujuedengji}})</text></view>
					<view v-else>失败</view>
					
					<view v-if="yeguaismz>0">{{yeguaismz}}<text style="font-size: 12px;">(LV.{{yeguaidengji}})</text>
					<view>
						<text style="font-size: 12px;" v-if="!zhongdubiaoji">中毒 &nbsp;</text>
						<text style="font-size: 12px;" v-if="!xuanyunbiaoji">晕眩 &nbsp;</text>
						<text style="font-size: 12px;" v-if="!baojibiaoji">暴击 &nbsp;</text>
					</view>
					</view>
					<view v-else>失败</view>
				</view>
				<!-- 分割线 -->
				<u-divider></u-divider>
				
				<!-- 对战双方名称 -->
				<view class="shuangfmc">
					<!-- 主角信息 -->
					<view>
						<view :animation="animationData2" :class="zhujuegjlshow">
							<view>-{{yeguaigjl}}</view>
						</view>
						<view :animation="animationData4" class="animation">
							<view>{{zhujuename}}</view>
						</view>
					</view>
					<!-- 野怪信息 -->
					<view>
						<view :animation="animationData3" :class="yeguaigjlshow">
							<view>-{{zhujuegjl}}</view>
						</view>
						<view :animation="animationData" class="animation">
						    <text>{{yeguainame}}</text>
						</view>
					</view>
				</view>
				<!-- 普通攻击按键 -->
				<button v-if="gongjijiantype==1" @click="zhujueGj" :disabled="gongjishow">攻击</button>
				<!-- 分割线 -->
				<u-divider></u-divider>
				<view v-if="yeguaismz<=0">
					<text style="margin: 20%;font-size: 35rpx;">【{{yeguainame}}】 失败</text>
					<!-- 分割线 -->
					<u-divider></u-divider>
					<view v-if="newgetjineng">
						<text v-for="jineng of newgetjineng" :key="jineng">【{{jineng}}】</text>
					</view>
					<view v-if="newgetwuzi">
						<text v-for="wuzi of newgetwuzi" :key="wuzi['名称']">【{{wuzi["名称"]}}x{{wuzi["数量"]}}】</text>
					</view>
					<view>
						<text>经验:{{yeguaijingyanzhi}}</text>
					</view>
					<view>
						<text>等级:{{zhujuedengji}}</text>
					</view>
					<view>
						<button v-if="gongjijiantype==3" @click="duzhanshow=false" >继续</button>
					</view>
				</view>
				<view v-else-if="zhujuesmzcopy<=0">
					<view>
						<text style="margin: 20%;font-size: 35rpx;">【{{zhujuename}}】 失败</text>
						<!-- 分割线 -->
						<u-divider></u-divider>
						<!-- <text style="margin: 30%;font-size: 20px;">请重新开始</text> -->
					</view>
					<view>
						<button v-if="gongjijiantype==2" @click="reStart(0)" >重新开始</button>
					</view>
				</view>
				<view v-else>
					<view class="zhujujinengclass">
						<button :disabled="jinengcdmap[jineng]" v-for="jineng of zhujuejinenglist" :key="jineng" @click="skillSetting(jineng,1)">{{jineng}}</button>
					</view>
					<!-- 分割线 -->
					<u-divider></u-divider>
					<view class="zhujuwuzizcclass">
						<button :disabled="wuzicdmap[item['名称']]" v-for="item in zhujuewuzilist" :key="item['名称']" @click="materialSetting(item,2)">{{item['名称']}}x{{item['数量']}}</button>
					</view>
				</view>
			</view>
		</view>
		<!-- 剧情结束 -->
		<u-modal :show="juqingjieshushow" confirmText="再次启程" @confirm="reStart(1)">
			<view class="slot-content">
				<rich-text nodes="一路走来总有艰辛,但是不忘初心方见曙光"></rich-text>
			</view>
		</u-modal>
		<!-- 背包 -->
		<u-modal :show="beibaoshow" confirmText="关闭" @confirm="beibaoshow=false">
			<view class="beibaoclass">
				<view>{{zhujuename}}</view>
				<view class="beibaozhujuexinxi">
					<view>LV.{{zhujuedengji}}</view>
					<view>生命值：{{zhujuesmzcopy}}</view>
					<view>攻击力：{{zhujuegjl}}</view>
					<view>经验值：{{zhujuejingyanzhi}}</view>
					<view>技能：{{zhujuejinenglist.join(',')}}</view>
					<view>
						物资：<text v-for="item of zhujuewuzilist" :key="item['名称']">【{{item["名称"]}}X{{item['数量']}}】 </text>
					</view>
					<!-- 分割线 -->
					<u-divider></u-divider>
				</view>
				<view class="zhujujinengallclass">
					<button style="width: 110rpx; margin: 2rpx; font-size: 28rpx;" v-for="jineng of zhujuealljinenglist" @click="updatejineng(jineng)">{{jineng}}</button>
					
				</view>
				<!-- 分割线 -->
				<u-divider></u-divider>
				<view class="zhujuwuziclass">
					<view v-for="wuzi of zhujueallwuzilist" :key="wuzi['名称']" style="margin: 3rpx;">
						<view @click="getwuzi(wuzi['名称'])">{{wuzi['名称']}}</view>
						<view><text @click="wuziAdd(wuzi['名称'])">+</text><text>{{wuzi['数量']}}</text><text @click="wuziMinus(wuzi['名称'])">-</text></view>
					</view>
				</view>
				<!-- 分割线 -->
				<u-divider></u-divider>
				<view class="zhujuwuziclass">
					<view v-for="wuzi of zhujueallteshuwujianlist" :key="wuzi['名称']">
						<view @click="teshuWuJian(wuzi)">{{wuzi['名称']}}【{{wuzi['数量']}}】</view>
					</view>
				</view>
				<!-- 分割线 -->
				<u-divider></u-divider>
				<view>
					<button :disabled="shijianzhuisushow" @click="shijianzhuiSu(shiguangzhuisudaoju)">{{shiguangzhuisudaoju['名称']}}</button>
				</view>
			</view>
		</u-modal>
		<!-- 云游 -->
		<u-modal :show="yunyoushow" confirmText="关闭" @confirm="yunyoushow=false">
			<view class="yunyouclass" id="yunyoushijianid">
				<view v-for="(line, index) in yunyouriji" :key="index">
					<view v-if="line && line['天气']" style="font-size: 13px;">天气：{{line['天气']}}</view>
					<view v-if="line && line['情节']" style="font-size: 15px;">{{line['情节']}}</view>
					<view v-if="line && line['获得物资']" style="font-size: 12px;">
						<view v-for="(k, v) of line['获得物资']" :key="k+v">
							获得：{{k['名称']}}【{{k['数量']}}】
						</view>
					</view>
					<!-- 分割线 -->
					<u-divider></u-divider>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 云游显示
				yunyoushow:false,
				// 背包显示
				beibaoshow:false,
				// 剧情结束标志
				juqingjieshushow:false,
				// 攻击键类型，1进攻，2重新开始
				gongjijiantype:1,
				// 攻击键禁用，用来设置攻击CD，以防攻速过快
				gongjishow:false,
				// 野怪掉血效果class样式
				yeguaigjlshow:"yeguaigjlshow",
				// 主角掉血效果class样式
				zhujuegjlshow:"zhujuegjlshow",
				// 主角名称，没有在json读取到就默认
				zhujuename:"主角",
				// 野怪名称，没有在json读取到就默认
				yeguainame:"野怪",
				// 主角攻击力
				zhujuegjl:0,
				// 野怪攻击力
				yeguaigjl:0,
				// 主角生命值，用于恢复生命值
				zhujuesmz:0,
				// 野怪生命值
				yeguaismz:0,
				// 野怪经验值
				yeguaijingyanzhi:0,
				//主角经验值
				zhujuejingyanzhi:0,
				// 主角和野怪攻击效果和掉血效果特效
				animationData4:{},
				animationData3:{},
				animationData2:{},
				animationData: {},
				animation:null,
				animation2:null,
				animation3:null,
				animation4:null,
				// 进入对战按钮禁用，以防已经战斗了还可以按
				duzhandisabled:false,
				// 对战弹窗显示
				duzhanshow:false,
				// 剧情json
				plotDatas:{},
				// 主角json
				protagonistDatas:{},
				// 配角json
				minorDatas:{},
				// 天气json
				weatherDatas:{},
				// 技能json
				skillDatas:{},
				// 野怪json
				monstersDatas:{},
				// BOSSjson
				bossDatas:{},
				// 物资json
				materialDatas:{},
				// 等级json
				gradeDatas:{},
				// 背包json
				knapsackDatas:{},
				// 新剧情json
				newPlotDatas:{},
				// 时光追溯剧情json
				shiguangPlotDatas:{},
				// 云游json
				yunyouDatas:{},
				// 技能设定
				skillMap:["晕眩","中毒","暴击","无敌",""],
				materialEffect:["补血","补法力","伤害","晕眩","中毒"],
				// 本章剧情正文，用于显示动画效果，所以存list里
				lines: [],
				// 正文背景图片
				background_image:"",
				// 剧情索引，多章节，用来进入下一章节和最后章节
				juqingindex:0,
				// 对话索引，多对话，用来进入下一个对话和结束对话
				duihuaindex:0,
				// 对话list，用来存本次所有对话
				duihuadatas:[],
				// 剧情正文内容
				qingjiedatas:"",
				// 单次对话的内容
				duihuacontent:'',
				// 对话弹窗显示
				duihuashow:false,
				// 对话弹窗按钮文本
				duihuaanniu:"继续",
				// 按钮显示，用于正文显示完才显示按钮
				juqinganniushow:false,
				// 控制按钮用途，0是下一张，1是对话，2是战斗
				juqinganniu:0,
				// 主角生命值复制，用于对战时显示
				zhujuesmzcopy:0,
				// 主角最高等级
				maxDengji:1,
				// 主角技能
				zhujuejinenglist:[],
				// 主角物资
				zhujuewuzilist:[],
				// 晕眩标记
				xuanyunbiaoji:1,
				// 晕眩持续时间
				yunxuanxiaoguoshijian:0,
				// 技能cd阶段显示
				jinengcdmap:{
					'晕眩':false,
					'中毒':false,
					'暴击':false
				},
				// 中毒效果时长
				zhongduxiaoguoshijian:0,
				// 中毒标记
				zhongdubiaoji:1,
				// 暴击标记
				baojibiaoji:1,
				// 野怪miss
				yeguaimiss:0,
				// 主角miss
				zhujuemiss:0,
				// 新获得技能
				newgetjineng:[],
				// 新获得物资
				newgetwuzi:[],
				// 野怪等级
				yeguaidengji:1,
				// 主角等级
				zhujuedengji:1,
				// 所有技能
				zhujuealljinenglist:[],
				// 所有物资
				zhujueallwuzilist:[],
				//所有特殊物件
				zhujueallteshuwujianlist:[],
				// 物资效果CD
				wuzicdmap:{
					'晕眩':false,
					'中毒':false,
					'暴击':false,
					'治疗':false
				},
				// 新剧情条件
				newtiaojianname:"",
				// 新剧情数量
				newtiaojiannum:0,
				// 特殊标记
				teshubiaoji:"0",
				// 新剧情标记
				newjuqingbiaoji:0,
				// 云游日志
				yunyouriji:[],
				// 时光追溯到距
				shiguangzhuisudaoju:{},
				// 时光追溯显示标记
				shijianzhuisushow:true,
				// 时光追溯世界
				shiguangzhuisushijie:0,
				// 底部按钮1
				dibuanniu1: '背包',
				// 底部按钮2
				dibuanniu2: '云游'
			}
		},
		onLoad() {
		},
		onUnload() {
		},
		onload(){
		},
		mounted() {
			// 加载所有json数据
			if(this.intoJsondatas()){
				if(uni.getStorageSync("juqingindex")){
					this.juqingindex = uni.getStorageSync("juqingindex")
				}else{
					this.juqingindex = 0
					uni.setStorageSync("juqingindex",this.juqingindex)
				}
				// 获取主角名称
				this.getZhujueName();
				// 加载剧情正文
				this.juqing();
				// 获取主角最大等级
				this.maxDengji = this.getMaxDengji();
			}
		},
		methods: {
			// JSON初始化
			intoJsondatas(){
				// 剧情json
				this.plotDatas = require('@/static/剧情.json')
				this.dibuanniu1 = this.plotDatas['按钮1']
				this.dibuanniu2 = this.plotDatas['按钮2']
				// 主角json
				// this.protagonistDatas = require('@/static/主角.json')
				this.getZhujuJsonDatas(1);
				// 配角json
				this.minorDatas = require('@/static/配角.json')
				// 天气json
				this.weatherDatas = require('@/static/天气.json')
				// 技能json
				this.skillDatas = require('@/static/技能.json')
				// 野怪json
				this.monstersDatas = require('@/static/野怪.json')
				// BOSSjson
				this.bossDatas = require('@/static/BOSS.json')
				// 物资json
				this.materialDatas = require('@/static/物资.json')
				// 等级json
				this.gradeDatas = require('@/static/等级.json')
				// 背包
				this.knapsackDatas = require('@/static/背包.json')
				// 新剧情json
				this.newPlotDatas = require('@/static/新剧情.json')
				this.newtiaojianname = this.newPlotDatas['条件道具']
				this.newtiaojiannum = this.newPlotDatas['条件数量']

				// 时光追溯剧情json
				this.shiguangPlotDatas = require('@/static/时光追溯剧情.json')

				// 云游json
				this.yunyouDatas = require('@/static/云游.json')
				return true;
			},
			getZhujuJsonDatas(type){
				// 如果时重新开始就不用从本地读取了
				if(type==1){
					// 查看本地是否有数据，没有的话再从json获取
					let protagonistDatas = uni.getStorageSync("protagonistDatas")
					if(protagonistDatas){
						this.protagonistDatas = protagonistDatas
					}else{
						// 主角json
						this.protagonistDatas = require('@/static/主角.json');
						uni.setStorageSync("protagonistDatas", this.protagonistDatas)
					}
				}else{
					// 主角json
					this.protagonistDatas = require('@/static/主角.json');
					uni.setStorageSync("protagonistDatas", this.protagonistDatas)
				}
			},
			// 技能设定
			skillSetting(jineng, type){
				let xiaoguo = this.skillDatas[jineng]["效果"]
				if(xiaoguo=='晕眩'){
					this.dizzinessEffect(this.skillDatas[jineng], jineng, type)
				}
				if(xiaoguo=='中毒'){
					this.zhongduxiaoguo(this.skillDatas[jineng], jineng, type)
				}
				if(xiaoguo=='暴击'){
					this.baojixiaoguos(this.skillDatas[jineng], jineng, type)
				}
			},
			// 物资设定
			materialSetting(item, type){
				// 数量小于0不执行
				let num = item['数量']
				if (num<=0){
					return
				}
				let xiaoguo = this.materialDatas[item['名称']]['效果']
				if(xiaoguo=="晕眩"){
					this.dizzinessEffect(this.materialDatas[item['名称']], item['名称'], type)
				}
				if(xiaoguo=="中毒"){
					this.zhongduxiaoguo(this.materialDatas[item['名称']], item['名称'], type)
				}
				if(xiaoguo=="暴击"){
					this.baojixiaoguos(this.materialDatas[item['名称']], item['名称'], type)
				}
				if(xiaoguo=="治疗"){
					this.zhiliaoxiaoguo(this.materialDatas[item['名称']], item['名称'], type)
				}
			},
			// 晕眩效果
			dizzinessEffect(jinengdatas, key, type){
				const that=this;

				if(type==1){
					// 晕眩按钮显示
					that.jinengcdmap[key] = true
				}else{
					that.wuzicdmap[key] = true
					let zbnum = this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量']
					zbnum = zbnum-1
					this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量'] = zbnum
					if(zbnum<=0){
						this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === key), 1)
					}
					
					// let xzbnum = this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量']
					// this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量'] = xzbnum-1
					
					// this.updateStorageSyncx();
				}
				
				let yunxuandata = jinengdatas;
				
				let jinengmiss = Number(yunxuandata["MISS率"])
				
				// 晕眩cd
				let xunyuancds = Number(yunxuandata['冷却时间'])*1000
				
				// 获取技能miss概率
				let misslv = this.missRandomInt(jinengmiss)
				
				if(misslv){
					// 效果持续时间
					this.yunxuanxiaoguoshijian = Number(yunxuandata['持续时间'])*1000
					// 晕眩标记
					this.xuanyunbiaoji = 0;
				}

				// 用于攻击CD
				setTimeout(() => {
					if(type==1){
						that.jinengcdmap[key] = false
					}else{
						this.wuzicdmap[key] = false
					}
				}, xunyuancds)
			},
			async zhongduxiaoguo(jinengdatas, key, type){
				const that=this;

				if(type==1){
					// 中毒按钮显示
					that.jinengcdmap[key] = true
				}else{
					that.wuzicdmap[key] = true
					let zbnum = this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量']
					zbnum = zbnum-1
					this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量'] = zbnum
					
					if(zbnum<=0){
						this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === key), 1)
					}
					
					// let xzbnum = this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量']
					// this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量'] = xzbnum-1
					
					// this.updateStorageSyncx();
				}
				
				let zhongdudata = jinengdatas;

				// 中毒cd
				let zhongducds = Number(zhongdudata['冷却时间'])*1000
				// 效果持续时间
				this.zhongduxiaoguoshijian = Number(zhongdudata['持续时间'])*1000
				// 攻击力
				let zhongdugongili = Number(zhongdudata['攻击力'])
				
				// 中毒标记
				this.zhongdubiaoji = 0;
				
				// 用于中毒掉血持续
				let chushishuzhi = 0;
				
				let jinengmiss = Number(zhongdudata["MISS率"])
				// 获取技能miss概率
				let misslv = this.missRandomInt(jinengmiss)
				
				let ygys = 0
				
				if(misslv){
					// 中毒持续掉血
					let zhongdufx = setInterval(function() {
						// if(that.yeguaismz<=0){
						// 	// 攻击键，继续
						// 	this.gongjijiantype=3
						// 	// 按键类型为0
						// 	this.juqinganniu=0;
						// 	// 按键名称继续
						// 	this.duihuaanniu="继续"
						// 	console.log("中毒结束",this.gongjijiantype)
						// }
						if(chushishuzhi<that.zhongduxiaoguoshijian){
							if(that.yeguaismz<=0){
								// 野怪生命值小于等于0，继续
								// 攻击键，继续
								// this.gongjijiantype=3
								// console.log("中毒结束")
								clearInterval(zhongdufx);
								// ygys = 1
								// // that.yeguaishengmingzhijieshu();
								// if(ygys==1){
								// 	console.log("中毒ing")
								// 	that.yeguaishengmingzhijieshu();
								// }
								return
							}
							// 持续扣血
							that.yeguaismz = that.yeguaismz-Number(zhongdugongili)
							if(that.yeguaismz<=0){
								that.yeguaishengmingzhijieshu();
							}
						}
						chushishuzhi = chushishuzhi+1000
						// 中毒标记用于显示战斗时的状态
					},that.zhongduxiaoguoshijian)
				}	
				// 中毒CD
				setTimeout(() => {
					if(type==1){
						// 中毒按钮显示
						that.jinengcdmap[key] = false
					}else{
						that.wuzicdmap[key] = false
					}
				  // 中毒标记用于显示战斗时的状态
				  that.zhongdubiaoji = 1
				}, zhongducds)
			},
			// 暴击效果
			baojixiaoguos(jinengdatas, key, type){
				const that=this;

				if(type==1){
					// 暴击按钮显示
					that.jinengcdmap[key] = true
				}else{
					that.wuzicdmap[key] = true
					let zbnum = this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量']
					zbnum = zbnum-1
					this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量'] = zbnum
					
					if(zbnum<=0){
						this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === key), 1)
					}
					
					// let xzbnum = this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量']
					// this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量'] = xzbnum-1
					
					// this.updateStorageSyncx();
				}
				
				let baojidata = jinengdatas;
				
				// 暴击cd
				let baojicds = Number(baojidata['冷却时间'])*1000

				// 暴击攻击力
				let baojigongili = Number(baojidata['攻击力'])
				
				let jinengmiss = Number(baojidata["MISS率"])
				// 获取技能miss概率
				let misslv = this.missRandomInt(jinengmiss)
				if(misslv){
					that.yeguaismz = that.yeguaismz-Number(baojigongili)
					if(that.yeguaismz<=0){
						that.yeguaishengmingzhijieshu()
					}
				}
				
				// 野怪生命值小于等于0，继续
				// if(that.yeguaismz<=0){
				// 	console.log("暴击结束")
				// 	that.gongjijiantype=3
				// 	await that.yeguaishengmingzhijieshu()
				// }
				
				// 暴击标记
				this.baojibiaoji = 0;
				
				// 暴击CD
				setTimeout(() => {
					if(type==1){
						// 暴击按钮显示
						that.jinengcdmap[key] = false
					}else{
						that.wuzicdmap[key] = false
					}
				  this.baojibiaoji = 1;
				}, baojicds)
				
			},
			// 治疗效果
			zhiliaoxiaoguo(jinengdatas, key, type){
				const that=this;
				
				if(type==1){
					// 治疗按钮显示
					that.jinengcdmap[key] = true
				}else{
					that.wuzicdmap[key] = true
					let zbnum = this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量']
					zbnum = zbnum-1
					this.zhujuewuzilist[this.zhujuewuzilist.findIndex(item => item['名称'] === key)]['数量'] = zbnum
					if(zbnum<=0){
						this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === key), 1)
					}
					
					// let xzbnum = this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量']
					// this.zhujueallwuzilist[this.zhujueallwuzilist.findIndex(item => item['名称'] === key)]['数量'] = xzbnum-1
					
				}
				
				let zhiliaodata = jinengdatas;
				
				// 治疗cd
				let zhiliaocds = Number(zhiliaodata['冷却时间'])*1000
				
				// 治疗攻击力（恢复值）
				let zhiliaogongili = Number(zhiliaodata['攻击力'])
				
				let jinengmiss = Number(zhiliaodata["MISS率"])
				// 获取技能miss概率
				let misslv = this.missRandomInt(jinengmiss)
				if(misslv){
					let zhujuesmzz = that.zhujuesmzcopy + Number(zhiliaogongili)
					
					if(zhujuesmzz>=that.zhujuesmzcopy){
						that.zhujuesmzcopy = that.zhujuesmz
					}else{
						that.zhujuesmzcopy = zhujuesmzz
					}
					
					
				// this.updateStorageSyncx();
				}
				// 暴击CD
				setTimeout(() => {
					if(type==1){
						// 暴击按钮显示
						that.jinengcdmap[key] = false
					}else{
						that.wuzicdmap[key] = false
					}
				}, zhiliaocds)
			},
			// 处理正文，将正文分段，用于动画显示
			async splitText(message) {
				// 动画时间
				let delay = 0
				// 用于存放文字
				let sentence = ''
				// 全局正文list，清空正文list，只显示本章内容
				this.lines = []
				// 局部正文list
				let lines = []
				// 循环正文字符
				for(let index in message){
					// 存正文字符
					sentence = sentence+message[index]
					// 长度等于三十或者已经是最后一段文字
					if((index>0 && index%30==0) || index==message.length-1){
						// 加入正文list中
						lines.push(sentence)
						// 清空已经存好的文字
						sentence=""
					}
				}
				// 正文每行用动画效果
				for(let line of lines){
					await this.hanshu(line, delay)
				}
			},
			// 正文动画效果
			async hanshu(line,delay){
				// 每一段时间+300毫秒，这样就会一段一段显示
				delay += 300
				// 将正文数据加入全局正文list
				this.lines.push(line)
				// 休眠
				await this.sleep(delay)
				// 屏幕跟随一起下滑
				let element = document.getElementById("backgroundXText");
				element.scrollTop = element.scrollHeight;
			},
			// 休眠
			sleep(delay){
				return new Promise((resolve)=>setTimeout(resolve,delay))
			},
			// 加载剧情
			async juqing(){

				let plotDatas = this.plotDatas

				if(this.newjuqingbiaoji!=0){
					plotDatas = this.newPlotDatas;
				}
				if(this.shiguangzhuisushijie!=0){
					plotDatas = this.shiguangPlotDatas;
				}
				
				this.juqingindex = uni.getStorageSync("juqingindex")
				
				this.juqinganniushow = false;

				if(plotDatas['剧情'].length-1 == this.juqingindex){
					if(this.protagonistDatas[this.zhujuename]['时间追溯者标记']==1 && this.teshubiaoji=="0"){
						this.shijianzhuisushow= this.protagonistDatas[this.zhujuename]['时间追溯者标记']!=1	
					}
				}
				// 所有剧情展示完就结束
				if(plotDatas['剧情'].length == this.juqingindex){
					this.juqingjieshushow=true;
					return
				}
				// 获取背景图片
				this.background_image = plotDatas['剧情'][this.juqingindex]['背景图片']
				// 获取情节
				this.qingjiedatas=plotDatas['剧情'][this.juqingindex]['情节']
				// 获取对话
				this.duihuadatas = plotDatas['剧情'][this.juqingindex]['对话']
				// 野怪
				this.yeguai = plotDatas['剧情'][this.juqingindex]['野怪']
				// 先展示正文内容动画效果
				await this.splitText(this.qingjiedatas)
				// 正文动画显示完就显示按钮
				this.juqinganniushow=true
				// 对话索引复位
				this.duihuaindex=0
				// 如果有对话，按钮设置为对话按钮
				if(this.duihuadatas.length>0){
					console.log("111:",this.juqingindex)
					this.juqinganniu=1
					this.duihuaanniu="继续"
					// 调用第一段对话
					await this.duihua();
					console.log("222:",this.juqingindex)
					// this.juqingindex = Number(this.juqingindex) + 1
					// uni.setStorageSync("juqingindex", this.juqingindex)
				}else{
					if(this.yeguai){
						// 开启对战按钮
						this.duzhandisabled=false
						// 对话弹窗关闭
						this.duihuashow = false
						// 按钮文字变成对战
						this.duihuaanniu="对战"
						// 按钮值改为2对战
						this.juqinganniu=2
						// this.juqingindex = Number(this.juqingindex) + 1
						// uni.setStorageSync("juqingindex", this.juqingindex)
						return
					}else{
						// this.yeguaishengmingzhijieshu()
						// 对话弹窗关闭
						this.duihuashow = false
						// 关闭对战弹窗
						this.duzhanshow=false;
						// 控制按钮用途，复位
						this.juqinganniu=0
						// 剧情索引加一，进入下一章节
						// this.juqing()
						this.juqingindex = Number(this.juqingindex) + 1
						uni.setStorageSync("juqingindex", this.juqingindex)
					}
				}
			},
			// 对话
			duihua(){
				console.log("3333:",this.juqingindex)
				
				// 对话内容赋值局部变量
				let duihuadatas = this.duihuadatas;
				// 所有对话结束
				if(duihuadatas.length==this.duihuaindex){
					console.log("duihua111:",this.duihuaindex, this.duihuadatas.length, duihuadatas.length==this.duihuaindex)
					// 没有野怪信息直接下一章
					if(!this.yeguai){
						// 对话弹窗关闭
						this.duihuashow = false
						// 关闭对战弹窗
						this.duzhanshow=false;
						// 控制按钮用途，复位
						this.juqinganniu=0
						// 剧情索引加一，进入下一章节
						// this.juqing()
						this.juqingindex = Number(this.juqingindex) + 1
						uni.setStorageSync("juqingindex", this.juqingindex)
						console.log("444:",this.juqingindex)
						this.duihuaindex=0
						return
					}
					else{
						// 开启对战按钮
						this.duzhandisabled=false
						// 对话弹窗关闭
						this.duihuashow = false
						// 按钮文字变成对战
						this.duihuaanniu="对战"
						// 按钮值改为2对战
						this.juqinganniu=2
						console.log("555:",this.juqingindex)
						return
					}
					
					console.log("666:",this.juqingindex)
					
				}
				console.log("777:",this.juqingindex)
				// 获取对话角色名
				let juese = duihuadatas[this.duihuaindex]["角色"]
				// 获取对话内容
				let neirong = duihuadatas[this.duihuaindex]["内容"]
				// 获取角色头像
				let touxiang = this.getJuseTouxiang(juese)
				// 清空对话内容
				let content = ""
				// 头像存在内容添加头像图片
				if(touxiang){
					content = content+"<img src='"+touxiang+"' width='82' height='82' >"
				}
				// 拼接对话内容
				content = content +"<br>"+juese+":"+"<br>"+neirong
				// 局部变量赋值全局变量
				this.duihuacontent = content
				// 对话索引加一
				this.duihuaindex = this.duihuaindex+1
				
				console.log("duihua222:",this.duihuaindex, this.duihuadatas.length)
				
				console.log("888:",this.juqingindex)
			},
			// 获取角色头像
			getJuseTouxiang(name){
				// 获取主角头像
				let protagonistname = this.protagonistDatas[name]
				// 获取配角头像
				let minorname = this.minorDatas[name]
				// 如果配角头像存在返回
				if(minorname){
					return minorname["头像"]
				}
				// 如果主角头像存在返回
				else if(protagonistname){
					return protagonistname["头像"]
				}else{
					return ""
				}
			},
			// 获取主角姓名
			getZhujueName(){
				Object.keys(this.protagonistDatas).forEach(key => {
				    this.zhujuename = key;
				});
				this.teshubiaoji = this.protagonistDatas[this.zhujuename]["特殊标记"]
				this.newjuqingbiaoji = this.protagonistDatas[this.zhujuename]["新世界标记"]
			},
			// 对战
			async getduzhanshow(){

				let plotDatas = this.plotDatas

				if(this.newjuqingbiaoji!=0){
					plotDatas = this.newPlotDatas;
				}
				if(this.shiguangzhuisushijie!=0){
					plotDatas = this.shiguangPlotDatas;
				}
				
				// 获取野怪名称
				this.yeguainame = plotDatas['剧情'][this.juqingindex]['野怪']
				
				console.log(this.monstersDatas["野怪"][this.yeguainame])
				
				// 野怪经验值
				this.yeguaijingyanzhi = Number(this.monstersDatas["野怪"][this.yeguainame]["经验值"])
				//主角经验值
				// this.zhujuejingyanzhi = Number(this.protagonistDatas[this.zhujuename]["经验值"])
				
				// 野怪等级
				this.yeguaidengji = Number(this.monstersDatas["野怪"][this.yeguainame]["等级"])
				// 主角等级
				// this.zhujuedengji = Number(this.protagonistDatas[this.zhujuename]["等级"])
				
				
				// 获取野怪攻击力
				this.yeguaigjl = Number(this.monstersDatas["野怪"][this.yeguainame]["攻击力"])
				// 攻击力 = 初始攻击力 * 等级
				this.yeguaigjl = this.yeguaigjl * this.yeguaidengji
				
				// 主角等级
				this.zhujuedengji = Number(this.protagonistDatas[this.zhujuename]['等级'])
				// 主角经验值
				this.zhujuejingyanzhi = Number(this.protagonistDatas[this.zhujuename]['经验值'])
				// 主角实时生命值
				this.zhujuesmzcopy = Number(this.protagonistDatas[this.zhujuename]['实时生命值'])
				// 主角生命值
				this.zhujuesmz = Number(this.protagonistDatas[this.zhujuename]['生命值'])
				// 主角攻击力
				this.zhujuegjl = Number(this.protagonistDatas[this.zhujuename]['攻击力'])
				
				// 获取野怪生命值
				this.yeguaismz = Number(this.monstersDatas["野怪"][this.yeguainame]["生命值"])
				// 生命值 = 初始生命值 * 等级
				this.yeguaismz = this.yeguaismz * this.yeguaidengji
				
				// 主角技能
				this.zhujuejinenglist = this.protagonistDatas[this.zhujuename]["技能"]
				// 主角物资
				this.zhujuewuzilist = this.protagonistDatas[this.zhujuename]["物资"]
				
				// 野怪miss率
				this.yeguaimiss = Number(this.monstersDatas["野怪"][this.yeguainame]["MISS率"])
				
				// 主角miss率
				 this.zhujuemiss = Number(this.protagonistDatas[this.zhujuename]["MISS率"])
				
				// 攻击键默认攻击
				this.gongjijiantype = 1;
				// 攻击键显示
				this.gongjishow=false;
				// 对战弹窗显示
				this.duzhanshow=true;
				// 对战按钮禁用，以防误触
				this.duzhandisabled=true;
				// 野怪攻击开始
				await this.duizhanrunning();
			},
			// 野怪攻击
			duizhanrunning() {
				// that = this
				// 主角生命值为0结束
				// if(this.zhujuesmz==0){
				// 	return
				// }
				// 野怪攻击动画和掉血动画
				this.animationData = {}
				this.animationData2 = {}
				// 页面关闭后清空数据
				this.animation = uni.createAnimation()
				this.animation2 = uni.createAnimation()
				
				// 主角脱战后生命值恢复
				// this.zhujuesmzcopy = this.zhujuesmz
				
				// 野怪攻击CD 是1秒
				let yeguaicd = 1000

				// next动画来回匀速作用
				let next = true
				
				// 用于晕眩技能暂停野怪攻击
				let xuanyunshuzhi = 0
				
				// 用于晕眩技能暂停野怪攻击标记
				let xuanyunshuzhibiaoji = 1
				
				// 晕眩效果时长
				let xuanyunxiaoguoshichang = 0
				
				let jubumissRandomInt = this.yeguaiMissRandomInt
				
				// 动画
				// setTimeout(() => {
					// 循环执行
					let dhx = setInterval(() => {
						// 用于晕眩技能暂停野怪攻击标记
						xuanyunshuzhibiaoji = this.xuanyunbiaoji
						// 晕眩效果时长
						xuanyunxiaoguoshichang = this.yunxuanxiaoguoshijian
						
						let misslv = jubumissRandomInt(this.yeguaimiss)

						// 野怪生命值大于0
						if(this.yeguaismz>0 && this.zhujuesmzcopy>0){
							// 晕眩标记
							if(xuanyunshuzhibiaoji){
								if (next) {
									// 攻击和掉血动画
									this.animation.translateX(-100).step()
									if(misslv){
										// 掉血动画
										this.animation2.translateX(0).translateY(0).opacity(1).step()
										// 扣掉主角生命值
										this.zhujuesmzcopy = this.zhujuesmzcopy - Number(this.yeguaigjl)
										// 攻击以后主角掉血样式开始显示
										this.zhujuegjlshow="";
									}
									this.animation2.translateX(0).translateY(-30).opacity(0).step()
									
								} else {
									this.animation.translateX(0).step()
								}
							}
							// 晕眩标记，使用了晕眩技能以后
							if(!xuanyunshuzhibiaoji){
								// 效果时间没有过去就加时间
								if(xuanyunshuzhi<=xuanyunxiaoguoshichang){
									xuanyunshuzhi = xuanyunshuzhi+1000
								}else{
									// 晕眩时间过了以后改变晕眩标记
									xuanyunshuzhibiaoji=1
									this.xuanyunbiaoji=1
								}
							}
							
							next = !next;
							this.animationData = this.animation.export()
							this.animationData2 = this.animation2.export()
							// 主角生命值为0结束
							if(this.zhujuesmzcopy<=0 && this.yeguaismz>0){
								this.animation.translateX(0).step()
								this.animationData = this.animation.export()
								
								this.animationData4 = {}
								this.animation4 = uni.createAnimation()
								this.animation4.translateX(0).opacity(1).step()
								this.animationData4 = this.animation4.export()
								
								// 主角生命值为0，攻击键禁用
								this.gongjishow = true;
								this.gongjijiantype=2
								clearInterval(dhx);
								return
							}
						}else{
							// 野怪生命值为0，野怪名字消失
							if(this.yeguaismz<=0 && this.zhujuesmzcopy>0){
								this.animation.translateX(0).opacity(1).step()
								this.animationData = this.animation.export()
								xuanyunshuzhibiaoji=1
								this.xuanyunbiaoji=1
								clearInterval(dhx);
								return
							}
							// 主角生命值为0，主角名字消失
							if(this.zhujuesmzcopy<=0 && this.yeguaismz>0){
								this.gongjijiantype=2
								this.animation.translateX(0).step()
								this.animationData = this.animation.export()
								
								this.animationData4 = {}
								this.animation4 = uni.createAnimation()
								this.animation4.translateX(0).opacity(1).step()
								this.animationData4 = this.animation4.export()
								
								// 主角生命值为0，攻击键禁用
								this.gongjishow = true;

								clearInterval(dhx);
								return
							}
							// 停止循环
							clearInterval(dhx);
							return
						}
					}, yeguaicd)
				// }, 700)
				// clearInterval(dhx );
				// dhx()
			},
			// 主角攻击
			async zhujueGj(){ 
			  // 主角攻击动画和掉血动画
			  this.animationData4 = {}
			  this.animationData3 = {}
			  this.animation4 = uni.createAnimation()
			  this.animation3 = uni.createAnimation()
			  this.animation4.translateX(100).step()
			  this.animation4.translateX(0).step()
			  this.animationData4 = this.animation4.export()
			  
			  // 获取主角miss概率
			  let misslv = this.missRandomInt(this.zhujuemiss)
			  // 没达到miss才能开始
			  if(misslv){
				  // 扣除野怪血
				  this.yeguaismz = this.yeguaismz-Number(this.zhujuegjl)
				  if(this.yeguaismz>0 && this.zhujuesmz<=0){
					  this.gongjishow = true;
					  this.gongjijiantype=2
					  return
				  }
				  // 野怪生命值为0
				  if(this.yeguaismz<=0 && this.zhujuesmzcopy>0){				  
						await this.yeguaishengmingzhijieshu();
						return
				  }
				  // 掉血动画
				  this.animation3.translateX(0).translateY(0).opacity(1).step()
			  }
			  this.animation3.translateX(0).translateY(-30).opacity(0).step()
			  this.animationData3 = this.animation3.export()

			  // 野怪掉血样式开启
			  this.yeguaigjlshow = ""
			  // 攻击键禁用
			  this.gongjishow=true
			  
			  // 用于攻击CD
			  setTimeout(() => {
				  this.gongjishow = false;
				setInterval(function() {
					this.gongjishow = false;
					},1000)
				}, 1000)
			},
			yeguaishengmingzhijieshu(){
				
				let plotDatas = this.plotDatas

				if(this.newjuqingbiaoji!=0){
					plotDatas = this.newPlotDatas;
				}
				if(this.shiguangzhuisushijie!=0){
					plotDatas = this.shiguangPlotDatas;
				}

				let newword = false

				this.newgetjineng = []
				this.newgetwuzi = [] 
				
				let hdjineng = plotDatas['剧情'][this.juqingindex]['获得技能']
				let hdwuzi = plotDatas['剧情'][this.juqingindex]['获得物资']

				// 主角特殊标记
				let zhujuetsbj = this.protagonistDatas[this.zhujuename]["特殊标记"]
				
				if(zhujuetsbj){
					if(hdjineng[zhujuetsbj]){

						this.newgetjineng = hdjineng[zhujuetsbj]
						
						// let hdalljineng = this.protagonistDatas[this.zhujuename]["技能"]
						
						// for(let data of hdjineng[zhujuetsbj]){
						// 	let panduan = hdalljineng.includes(data)
						// 	if(!panduan){
						// 		hdalljineng.push(data)
						// 	}
						// }
						// this.protagonistDatas[this.zhujuename]["技能"] = hdalljineng
						
						let xxhdalljineng = this.protagonistDatas[this.zhujuename]["已获取技能"]
						
						for(let data of hdjineng[zhujuetsbj]){
							let panduan = xxhdalljineng.includes(data)
							if(!panduan){
								xxhdalljineng.push(data)
							}
						}
						this.protagonistDatas[this.zhujuename]["已获取技能"] = xxhdalljineng
					}
					
					if(hdwuzi[zhujuetsbj]){

						this.newgetwuzi = hdwuzi[zhujuetsbj]
						
						// let hdallwuzi = this.protagonistDatas[this.zhujuename]["物资"]
						
						// let wuzimap = {}
						// for(let data of hdwuzi[zhujuetsbj]){
						// 	if(wuzimap[data['名称']]){
						// 		wuzimap[data['名称']] = wuzimap[data['名称']] + data['数量']
						// 	}else{
						// 		wuzimap[data['名称']] = data['数量']
						// 	}
						// }
						
						// for(let data of hdallwuzi){
						// 	if(wuzimap[data['名称']]){
						// 		data['数量'] = data['数量'] + wuzimap[data['名称']]
						// 		delete wuzimap[data['名称']]
						// 	}
						// }
						
						// for(let key in wuzimap){
						// 	hdallwuzi.push({
						// 		'名称':key,
						// 		'数量':wuzimap[key]
						// 	})
						// }					
						// this.protagonistDatas[this.zhujuename]["物资"] = hdallwuzi
						
						let xxhdallwuzi = this.protagonistDatas[this.zhujuename]["已获取物资"]

						let xxhdallwuziteshu = this.protagonistDatas[this.zhujuename]["特殊物件"]
						
						let xxwuzimap = {}
						let xxwuzimapteshu = {}

						for(let data of hdwuzi[zhujuetsbj]){
							let wuzixiaosguo = this.materialDatas[data['名称']]['效果']
							if(xxwuzimap[data['名称']]){
								if(['钥匙','回溯'].includes(wuzixiaosguo)){
									xxwuzimapteshu[data['名称']] = xxwuzimapteshu[data['名称']] + data['数量']
								}else{
									xxwuzimap[data['名称']] = xxwuzimap[data['名称']] + data['数量']
								}
								
							}else{
								if(['钥匙','回溯'].includes(wuzixiaosguo)){
									xxwuzimapteshu[data['名称']] = data['数量']
								}else{
									xxwuzimap[data['名称']] = data['数量']
								}
							}
							// 获得钥匙回到原本世界
							if(this.newtiaojianname == data['名称']&& zhujuetsbj!="0"){
								newword = true
							}
						}
						
						for(let data of xxhdallwuzi){
							let wuzixiaosguo = this.materialDatas[data['名称']]['效果']
							if(!['钥匙','回溯'].includes(wuzixiaosguo)){
								if(xxwuzimap[data['名称']]){
									data['数量'] = data['数量'] + xxwuzimap[data['名称']]
									delete xxwuzimap[data['名称']]
								}
							}
						}

						for(let data of xxhdallwuziteshu){
							let wuzixiaosguo = this.materialDatas[data['名称']]['效果']
							if(['钥匙','回溯'].includes(wuzixiaosguo)){
								if(xxwuzimapteshu[data['名称']]){
									data['数量'] = data['数量'] + xxwuzimapteshu[data['名称']]
									delete xxwuzimapteshu[data['名称']]
								}
							}
						}
						
						for(let key in xxwuzimap){
							xxhdallwuzi.push({
								'名称':key,
								'数量':xxwuzimap[key]
							})
						}
						
						this.protagonistDatas[this.zhujuename]["已获取物资"] = xxhdallwuzi

						for(let key in xxwuzimapteshu){
							xxhdallwuziteshu.push({
								'名称':key,
								'数量':xxwuzimapteshu[key]
							})
						}					
						this.protagonistDatas[this.zhujuename]["特殊物件"] = xxhdallwuziteshu

						// 获得钥匙回到原本世界
						if(newword){
							if(Number(this.protagonistDatas[this.zhujuename]["原世界坐标"])>0){
								this.juqingindex = Number(this.protagonistDatas[this.zhujuename]["原世界坐标"])-1
							}else{
								this.juqingindex = 0
							}
							
							this.protagonistDatas[this.zhujuename]["特殊标记"] = "0"
							this.teshubiaoji = this.protagonistDatas[this.zhujuename]["特殊标记"]
							uni.showToast({
								title: '获得特殊道具，将回到原世界',
								icon: 'none',
								duration: 4000
							});
						}
					}
				}
				
				// 攻击键，继续
				this.gongjijiantype=3
				// 按键类型为0
				this.juqinganniu=0;
				// 按键名称继续
				this.duihuaanniu="继续"
				
				console.log("战斗结束111：",this.juqingindex)

				// 剧情索引加一，进入下一章节
				this.juqingindex = Number(this.juqingindex) + 1
				uni.setStorageSync("juqingindex", this.juqingindex)
				
				// // 对话索引复位
				// this.duihuaindex = 0
				// 对战按钮复位
				this.duzhandisabled=false;
				// 对战弹窗关闭
				// this.duzhanshow=false;
				
				// 角色获胜就按钮类型为3
				this.gongjijiantype=3
				// 攻击键禁用
				this.gongjishow= true
				
				let olddengji = Number(this.protagonistDatas[this.zhujuename]["等级"])
				
				//主角经验值=原来的经验值 + 野怪经验值
				this.zhujuejingyanzhi = this.zhujuejingyanzhi + this.yeguaijingyanzhi
				
				this.zhujuedengji = this.dengjipanding(this.zhujuejingyanzhi)
				
				if(Number(this.zhujuedengji)>olddengji){
					let zhujue = require('@/static/主角.json');
					let zjgjl = Number(zhujue[this.zhujuename]["攻击力"])
					let zjsml = Number(zhujue[this.zhujuename]["生命值"])
					
					console.log("zhujue:",zhujue)
					
					console.log("zjgjl:",zjgjl)
					console.log("zjsml:",zjsml)
					
					console.log("this.zhujuedengji-olddengji:",this.zhujuedengji-olddengji)
					
					
					
					// 获取主角攻击力
					this.zhujuegjl = Number(this.protagonistDatas[this.zhujuename]["攻击力"])
					console.log("this.zhujuegjl111:",this.zhujuegjl)
					// 攻击力 = 初始攻击力 * 等级
					this.zhujuegjl = this.zhujuegjl + (zjgjl * (this.zhujuedengji-olddengji))
					
					console.log("(zjgjl * (this.zhujuedengji-olddengji):",(zjgjl * (this.zhujuedengji-olddengji)))
					console.log("this.zhujuegjl222:",this.zhujuegjl)
					
					
					// 获取主角生命值
					this.zhujuesmz = Number(this.protagonistDatas[this.zhujuename]["生命值"])
					// 生命值 = 初始生命值 * 等级
					this.zhujuesmz = this.zhujuesmz + (zjsml * (this.zhujuedengji-olddengji))
					
					// 获取主角实时生命值
					this.zhujuesmzcopy = Number(this.protagonistDatas[this.zhujuename]["实时生命值"])
					this.zhujuesmzcopy = this.zhujuesmzcopy + (zjsml * (this.zhujuedengji-olddengji))
				}
				
				this.protagonistDatas[this.zhujuename]['等级'] = String(this.zhujuedengji)
				this.protagonistDatas[this.zhujuename]['经验值'] = String(this.zhujuejingyanzhi)
				
				this.protagonistDatas[this.zhujuename]['实时生命值'] = this.zhujuesmzcopy
				this.protagonistDatas[this.zhujuename]['生命值'] = this.zhujuesmz
				this.protagonistDatas[this.zhujuename]['攻击力'] = this.zhujuegjl
				 
				uni.setStorageSync("protagonistDatas", this.protagonistDatas)
				
				console.log("战斗结束2222：",this.juqingindex)
				
			},
			// 重新开始
			reStart(type){
				console.log("type::",type)
				// type为1就是从第一章开始，为0就是当前章节开始
				if(type==1){
					console.log("type111111::",type)
					this.shiguangzhuisushijie=0
					this.newjuqingbiaoji=0
					this.juqingindex=0
					uni.setStorageSync("juqingindex",this.juqingindex)
					this.protagonistDatas = require('@/static/主角.json');
					// this.protagonistDatas[this.zhujuename]['实时生命值'] = this.protagonistDatas[this.zhujuename]['生命值']
					uni.setStorageSync("protagonistDatas", this.protagonistDatas)
				}else{
					console.log("type222222::",type)
					let zjsmz = this.protagonistDatas[this.zhujuename]['生命值']
					this.protagonistDatas[this.zhujuename]['实时生命值'] = zjsmz
					uni.setStorageSync("protagonistDatas", this.protagonistDatas)
				}
				// 剧情结束标志
				this.juqingjieshushow = false;
				// 按钮显示，用于正文显示完才显示按钮
				// this.juqinganniushow=false
				// 加载主角json
				this.getZhujuJsonDatas(1);
				// 关闭对战弹窗
				this.duzhanshow=false;
				// 控制按钮用途，复位
				this.juqinganniu=0
				// 加载剧情正文
				this.juqing();
				
				// // 显示主角动画
				// this.animationData4 = {}
				// this.animation4 = uni.createAnimation()
				// this.animation4.translateX(0).opacity(1).step()
				// this.animationData4 = this.animation4.export()

			},
			// 获取主角最大等级
			getMaxDengji(){
				let max = 0
				let dengji = ''
				for(let data in this.gradeDatas){
					if(max < this.gradeDatas[data]){
						max = this.gradeDatas[data]
						dengji = data
					}
				}
				return Number(dengji)
			},
			//miss 概率
			missRandomInt(misslv) {
				let sfmiss = false
				let randomnum =  Math.floor(Math.random() * (100 - 1 + 1) + 1);
				if(misslv <= randomnum){
					sfmiss = true
				}
				return sfmiss;
			},
			// 野怪miss率
			yeguaiMissRandomInt(misslv) {
				let sfmiss = false
				let randomnum =  Math.floor(Math.random() * (100 - 1 + 1) + 1);
				if(misslv <= randomnum){
					sfmiss = true
				}
				return sfmiss;
			},
			// 获取等级
			dengjipanding(jingyanzhi){
				let dengji = 1;
				for(let key in this.gradeDatas){
					if(jingyanzhi>=this.gradeDatas[key]){
						dengji = key;
						continue
					}
				}
				return dengji;
			},
			// 打开背包
			openBag(){
				this.zhujuesmz = this.protagonistDatas[this.zhujuename]["生命值"]
				this.zhujuesmzcopy = this.protagonistDatas[this.zhujuename]["实时生命值"]
				this.zhujuedengji = this.protagonistDatas[this.zhujuename]["等级"]
				this.zhujuegjl = this.protagonistDatas[this.zhujuename]["攻击力"]
				this.zhujuejingyanzhi = this.protagonistDatas[this.zhujuename]["经验值"]
				this.zhujuejinenglist = this.protagonistDatas[this.zhujuename]["技能"]
				this.zhujuewuzilist = this.protagonistDatas[this.zhujuename]["物资"]
				this.zhujuealljinenglist = this.protagonistDatas[this.zhujuename]["已获取技能"]
				this.zhujueallwuzilist = this.protagonistDatas[this.zhujuename]["已获取物资"]
				this.zhujueallteshuwujianlist = this.protagonistDatas[this.zhujuename]["特殊物件"]
				this.beibaoshow=true
			},
			// 更新技能
			updatejineng(jineng){
				let pandun = this.zhujuejinenglist.includes(jineng)
				if(pandun){
					this.zhujuejinenglist.splice(this.zhujuejinenglist.findIndex(item => item === jineng), 1)
				}else{
					if(this.zhujuejinenglist.length<=4){
						this.zhujuejinenglist.push(jineng)
					}
				}
			},
			// 物资增加
			wuziAdd(wuziname){

				// 物资
				let allmap = {}
				for(let data of this.zhujueallwuzilist){
					allmap[data['名称']] = data['数量']
				}

				// 物资
				let wuzilist = []
				for(let wuzi of this.zhujuewuzilist){
					wuzilist.push(wuzi['名称'])
				}
				// 物资
				if(wuzilist.includes(wuziname)){
					for(let wuzi of this.zhujuewuzilist){
						if(wuzilist.includes(wuzi['名称'])){
							if(wuzi['名称']==wuziname){
								if(allmap[wuzi['名称']]>0){
									wuzi['数量'] = wuzi['数量']+1
									allmap[wuzi['名称']] = allmap[wuzi['名称']]-1
								}
							}
						}
					}
				}else{
					if(allmap[wuziname]>=1){
						if(this.zhujuewuzilist.length<4){
							this.zhujuewuzilist.push({
								'名称':wuziname,
								'数量':1
							})
							allmap[wuziname] = allmap[wuziname]-1
						}
					}
				}
				
				let newlist = []
				for(let key in allmap){
					newlist.push({
						'名称':key,
						'数量':allmap[key]
					})
				}
				this.zhujueallwuzilist = newlist;
				this.updateStorageSyncx();
			},
			// 物资减少
			wuziMinus(wuziname){
				
				let allmap = {}
				for(let data of this.zhujueallwuzilist){
						allmap[data['名称']] = data['数量']
				}
				let wuzilist = []
				for(let wuzi of this.zhujuewuzilist){
					wuzilist.push(wuzi['名称'])
				}
				
				let zerobj = 0
				
				for(let wuzi of this.zhujuewuzilist){
					if(wuzilist.includes(wuzi['名称'])){
						if(wuzi['名称']==wuziname){
							if(wuzi['数量']>0){
								wuzi['数量'] = wuzi['数量']-1
								allmap[wuzi['名称']] = allmap[wuzi['名称']]+1
								if(wuzi['数量']<=0){
									zerobj=1
								}
							}
						}
					}
				}
				
				if(zerobj==1){
					this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === wuziname), 1)
				}
				
				let newlist = []
				for(let key in allmap){
						newlist.push({
							'名称':key,
							'数量':allmap[key]
						})
				}
				this.zhujueallwuzilist = newlist;
				
				this.updateStorageSyncx();
				
			},
			// 物资
			getwuzi(wuziname){
				let panduan = false
				let wuzinum = 0;
				for(let data of this.zhujuewuzilist){
					if(data['名称']==wuziname){
						wuzinum = data['数量']
						panduan = true
					}
				}
				if(panduan){
					this.zhujuewuzilist.splice(this.zhujuewuzilist.findIndex(item => item['名称'] === wuziname), 1)
					
					for(let data of this.zhujueallwuzilist){
						if(data['名称']==wuziname){
							data['数量'] = data['数量'] + wuzinum
						}
					}
				}
				this.updateStorageSyncx();
			},
			// 特殊物件使用
			teshuWuJian(wuzi){
				
				let wuziname = wuzi['名称']
				let xiaoguo = this.materialDatas[wuziname]['效果']

				if(xiaoguo=="回溯"){
					if(wuzi['数量']>0){
						
						this.protagonistDatas[this.zhujuename]["原世界坐标"] = String(this.juqingindex)
						this.protagonistDatas[this.zhujuename]["特殊标记"] = String(this.materialDatas[wuziname]["标记"])
						if(Number(this.materialDatas[wuziname]["世界坐标"])<this.juqingindex){
							this.juqingindex = Number(this.materialDatas[wuziname]["世界坐标"])
							uni.setStorageSync("juqingindex", this.juqingindex)
							this.juqing()
							
							wuzi['数量'] = wuzi['数量']-1
						}else{
							uni.showToast({
								title: '你将去往未来，无法回来',
								icon: 'none',
								duration: 4000
							});
							this.juqingindex = Number(this.materialDatas[wuziname]["世界坐标"])
							uni.setStorageSync("juqingindex", this.juqingindex)
							this.juqing()
							
							wuzi['数量'] = wuzi['数量']-1
						}
						this.beibaoshow=false	
						this.teshubiaoji = this.protagonistDatas[this.zhujuename]["特殊标记"]

						
						let zhuisuzhemap = {}
						let zhuisuzhename = ""
						for(let data in this.materialDatas){
							if(this.materialDatas[data]['效果']=='追溯者'){

								zhuisuzhename = data

								zhuisuzhemap={
									"名称":data,
									"数量":1
								}
							}
						}

						this.protagonistDatas[this.zhujuename]['时间追溯道具'] = zhuisuzhemap
						this.shiguangzhuisudaoju = this.protagonistDatas[this.zhujuename]['时间追溯道具']

						this.protagonistDatas[this.zhujuename]['时间追溯者标记'] = 1
						uni.setStorageSync("protagonistDatas", this.protagonistDatas)
					}	
				}
				if(xiaoguo=="钥匙"){
					if(wuzi['数量']>0 && wuzi['数量']>=this.newtiaojiannum){
						if(this.newtiaojianname == wuziname && this.newtiaojiannum<=wuzi['数量']){

							wuzi['数量'] = wuzi['数量']-this.newtiaojiannum
							this.newjuqingbiaoji=1
							this.protagonistDatas[this.zhujuename]["新世界标记"] = this.newjuqingbiaoji

							this.juqingindex=0
							uni.setStorageSync("juqingindex", this.juqingindex)

							this.beibaoshow=false
							this.juqing()
						}
					}
				}
			},
			// 云游
			async openYunYou(){
				 this.yunyoushow = true
				 await this.yunyoushijian();
			},
			yunyoushijian(){
				let that = this

				let juqing = that.yunyouDatas['剧情']
				if(juqing){
					let len = juqing.length
					if(len>=1){
						that.yunyouriji.push({"情节":"开始"+that.dibuanniu2})
						that.yunyouriji.push(that.yunyouDatas['剧情'][0])
						setInterval(function() {
							if(that.yunyoushow){
								let num = that.getRandomInt(0, len-1)
								that.yunyouriji.push(that.yunyouDatas['剧情'][num])
								let hdwuzi = that.yunyouDatas['剧情'][num]['获得物资']

								if(hdwuzi){
									let xxhdallwuzi = that.protagonistDatas[that.zhujuename]["已获取物资"]

									let xxhdallwuziteshu = that.protagonistDatas[that.zhujuename]["特殊物件"]

									let xxwuzimap = {}
									let xxwuzimapteshu = {}

									for(let data of hdwuzi){
										let wuzixiaosguo = that.materialDatas[data['名称']]['效果']
										if(xxwuzimap[data['名称']]){
											if(['钥匙','回溯'].includes(wuzixiaosguo)){
												xxwuzimapteshu[data['名称']] = xxwuzimapteshu[data['名称']] + data['数量']
											}else{
												xxwuzimap[data['名称']] = xxwuzimap[data['名称']] + data['数量']
											}
											
										}else{
											if(['钥匙','回溯'].includes(wuzixiaosguo)){
												xxwuzimapteshu[data['名称']] = data['数量']
											}else{
												xxwuzimap[data['名称']] = data['数量']
											}
										}
									}

									for(let data of xxhdallwuzi){
									let wuzixiaosguo = that.materialDatas[data['名称']]['效果']
									if(!['钥匙','回溯'].includes(wuzixiaosguo)){
										if(xxwuzimap[data['名称']]){
											data['数量'] = data['数量'] + xxwuzimap[data['名称']]
											delete xxwuzimap[data['名称']]
										}
									}
								}

								for(let data of xxhdallwuziteshu){
									let wuzixiaosguo = that.materialDatas[data['名称']]['效果']
									if(['钥匙','回溯'].includes(wuzixiaosguo)){
										if(xxwuzimapteshu[data['名称']]){
											data['数量'] = data['数量'] + xxwuzimapteshu[data['名称']]
											delete xxwuzimapteshu[data['名称']]
										}
									}
								}
								
								for(let key in xxwuzimap){
									xxhdallwuzi.push({
										'名称':key,
										'数量':xxwuzimap[key]
									})
								}					
								that.protagonistDatas[that.zhujuename]["已获取物资"] = xxhdallwuzi

								for(let key in xxwuzimapteshu){
									xxhdallwuziteshu.push({
										'名称':key,
										'数量':xxwuzimapteshu[key]
									})
								}					
								that.protagonistDatas[that.zhujuename]["特殊物件"] = xxhdallwuziteshu

								}
								let element = document.getElementById("yunyoushijianid");
								element.scrollTop = element.scrollHeight;

								if(that.yunyouriji.length>30){
									that.yunyouriji = that.yunyouriji.slice(0,20)
								}
							}
						},25000)
					}
				}
			},
			// 随机数
			getRandomInt(min,max){
				return Math.floor(Math.random()*(max-min+1))+min;
			},
			// 世界追溯
			shijianzhuiSu(shiguangzhuisudaoju){
				this.protagonistDatas[this.zhujuename]['时间追溯者标记'] = 0
				this.protagonistDatas[this.zhujuename]["进入时光追溯世界"] = 1
				this.shiguangzhuisushijie = this.protagonistDatas[this.zhujuename]["进入时光追溯世界"]
				this.juqingindex=0
				uni.setStorageSync("juqingindex", this.juqingindex)

				this.beibaoshow=false
				this.juqing()
			},
			// 更新
			updateStorageSyncx(){
				this.protagonistDatas[this.zhujuename]["生命值"] = this.zhujuesmz
				this.protagonistDatas[this.zhujuename]["实时生命值"] = this.zhujuesmzcopy
				this.protagonistDatas[this.zhujuename]["等级"] = this.zhujuedengji
				this.protagonistDatas[this.zhujuename]["攻击力"] = this.zhujuegjl
				this.protagonistDatas[this.zhujuename]["经验值"] = this.zhujuejingyanzhi
				this.protagonistDatas[this.zhujuename]["技能"] = this.zhujuejinenglist
				this.protagonistDatas[this.zhujuename]["物资"] = this.zhujuewuzilist
				this.protagonistDatas[this.zhujuename]["已获取技能"] = this.zhujuealljinenglist
				this.protagonistDatas[this.zhujuename]["已获取物资"] = this.zhujueallwuzilist
				this.protagonistDatas[this.zhujuename]["特殊物件"] = this.zhujueallteshuwujianlist
				uni.setStorageSync("protagonistDatas", this.protagonistDatas)
			}
			
		},
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}
	.jiemian{
		/* height: 100vh;
		width: 60vw; */
	}
	.backgroundX{
		/* margin-left: 20px; */
		height: 88vh;
		width: 60vw;
		background-size: 100% 100%;
		background-repeat:no-repeat;
	}
	.menuX{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		/* margin-left: 20px; */
		/* height: 10vh; */
		width: 60vw;
	}
	.backgroundXText{
		padding: 20px;
		height: 80vh !important;
		overflow-y:auto;
		/* -webkit-animation: 10s rowup linear infinite normal;
        animation: 10s rowup linear infinite normal;
        position: relative; */
		overflow-y:scroll;
		 text-shadow: 0 0 4px #6495ED,
		    0 0 4px #6495ED,
		    0 0 4px #6495ED,
		    0 0 4px #6495ED,
		    0 0 4px #6495ED,
		    0 0 4px #6495ED,
		    0 0 4px #6495ED;
	}

	.duihuakuangclass{
		height: 30vh !important;
		overflow-y:scroll;
	}
	.duizhanshow{
		width: 60%;
		height: 60%;
		position: absolute;
		background-color: white;
		z-index: 9999;
		border:0.5px solid;
		border-radius: 10px;
		overflow-y:scroll;
	}
	.beibaoclass{
		height: 60vh;
		overflow-y:scroll;
	}
	.yunyouclass{
		height: 70vh;
		overflow-y:scroll;
	}
	.duizhanshowbody{
		margin: 20px;
	}
	.shuangfmc{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
	.shuangfsmz{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
	.yeguaigjlshow{
		visibility: hidden;
	}
	.zhujuegjlshow{
		visibility: hidden;
	}
	.zhujujinengclass{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		flex-wrap:wrap;
	}
	.beibaozhujuexinxi{
		font-size: 25rpx;
		/* display: flex;
		flex-direction: row;
		justify-content: space-around;
		flex-wrap:wrap; */
	}
	.zhujujinengallclass{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap:wrap;
	}
	.zhujuwuziclass{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap:wrap;
	}
	.zhujuwuzizcclass{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		flex-wrap:wrap;
		height: 30rpx;
	}
	
/* 	@media screen and (max-width: 62rem){    	
	} */
	@media screen and (max-width: 48rem){    
		.content {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
		}
		.backgroundX{
			height: 90vh;
			width: 100vw;
		}
		.menuX{
			/* height: 10vh; */
			width: 100vw;
		}
		.duizhanshow{
			width: 90%;
			height: 60%;
			position: absolute;
			background-color: white;
			z-index: 9999;
			border:0.5px solid;
			border-radius: 10px;
		}
	}
</style>
